package lc;

public class Ex149 {

    class Solution {
        public int maxPoints(int[][] points) {
            int n = points.length, res = 2;
            for (int i = 0; i < n - 1; i++) {
                for (int j = i + 1; j < n; j++) {
                    int cur = 2; //至少两个点在直线上
                    for (int k = j + 1; k < n; k++) {
                        if (test(points[i][0], points[j][0], points[i][1], 
                                points[j][1], points[k][0], points[k][1])) cur++;
                    }
                    res = Math.max(res, cur);
                }
            }
            return res;
        }

        public boolean test(int x1, int x2, int y1, int y2, int x, int y) {
            return ((long)(y2 - y1)) * (x - x1) == ((long)(y - y1)) * (x2 - x1);
        }
    }

}
